﻿using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 可攻击对象信息
/// </summary>
public struct AttackObjectInfo
{
    public GameObject Pawn;
    public Vector2Int Pos;

    public AttackObjectInfo(GameObject pawn, Vector2Int pos)
    {
        Pawn = pawn;
        Pos = pos;
    }
}

/// <summary>
/// 关卡状态数据
/// </summary>
public struct RoundStateInfo
{
    public GameObject Pawn;
    public Vector2Int Pos;
    private Dictionary<Transform, int> ShowMoveMapDict;
    public static Dictionary<Transform, int> AttackRangeDict;
}

public static class GameState
{
    /// <summary>
    /// 焦点坐标
    /// </summary>
    public static Vector2Int FocusPos { set; get; }
    
    /// <summary>
    /// 焦点地图
    /// </summary>
    public static Transform FocusMapTransform { set; get; }
    
    /// <summary>
    /// 移动范围显示列表
    /// </summary>
    public static Dictionary<Transform,int> ShowMoveMapDict { set; get; }
    
    /// <summary>
    /// 攻击范围显示列表
    /// </summary>
    public static Dictionary<Transform, int> AttackRangeDict { set; get; }
    
    /// <summary>
    /// 可攻击对象列表
    /// </summary>
    public static List<AttackObjectInfo> AttackObjectInfos { set; get; }
    
    /// <summary>
    /// 当前攻击对象索引
    /// </summary>
    public static int AttackObjectIndex { set; get; }
    
    /// <summary>
    /// 地图大小
    /// </summary>
    public static Vector2Int MapSize { set; get; }
    
    /// <summary>
    /// 棋子到地图位置的映射表
    /// </summary>
    public static Dictionary<GameObject,Vector2Int> Pawn2PosDict;
    
    /// <summary>
    /// 地图位置到棋子的映射表
    /// </summary>
    public static Dictionary<Vector2Int,GameObject> Pos2PawnDict;
    
    /// <summary>
    /// 关卡当前状态
    /// </summary>
    public static RoundState CurRoundState;
    
    /// <summary>
    /// 关卡状态数据栈
    /// </summary>
    public static Stack<RoundStateInfo> StateDataStack;
    
    /// <summary>
    /// 地图实例列表，用于控制地图显示
    /// </summary>
    public static GameObject[,] MapGameObjects;

    public static void InitInfo()
    {
        FocusPos = new Vector2Int(0,0);
        MapSize = new Vector2Int(1,1);
        FocusMapTransform = null;
        ShowMoveMapDict = new Dictionary<Transform, int>();
        AttackRangeDict = new Dictionary<Transform, int>();
        Pawn2PosDict = new Dictionary<GameObject,Vector2Int>();
        Pos2PawnDict = new Dictionary<Vector2Int, GameObject>();
        AttackObjectInfos = new List<AttackObjectInfo>();
        MapGameObjects = null;
    }
    
    public static void ResetInfo()
    {
        FocusPos = new Vector2Int(0,0);
        MapSize = new Vector2Int(1,1);
        FocusMapTransform = null;
        ShowMoveMapDict.Clear();
        AttackRangeDict.Clear();
        Pawn2PosDict.Clear();
        Pos2PawnDict.Clear();
        AttackObjectInfos.Clear();
        MapGameObjects = null;
    }
}